package com.ego.manage.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ego.commons.pojo.EasyUIDataGrid;
import com.ego.commons.pojo.EgoResult;
import com.ego.manage.service.TbItemService;

@Controller
public class TbItemController {

	@Resource
	private TbItemService tbItemServiceImpl;
	/**
	 * 商品显示
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("item/list")
	@ResponseBody
	public EasyUIDataGrid show(int page,int rows) {
		return tbItemServiceImpl.show(page, rows);
	}
	
	/**
	 * 显示商品明细
	 * @return
	 */
	@RequestMapping("rest/page/item-edit")
	public String itemEdit() {
		return "item-edit";
	}
	/**
	 * 删除商品
	 * @return
	 */
	@RequestMapping("rest/item/delete")
	@ResponseBody
	public EgoResult delete(String ids) {
		//商品状态实体类
		EgoResult egoResult = new EgoResult();
		int index = tbItemServiceImpl.update(ids, (byte)3);
		//如果成功返回200状态
		if(index == 1) {
			egoResult.setStatus(200);
		}
		return egoResult;
	}
	/**
	 * 商品下架
	 * @param ids
	 * @return
	 */
	@RequestMapping("rest/item/instock")
	@ResponseBody
	public EgoResult instock(String ids) {
		//商品状态实体类
		EgoResult egoResult = new EgoResult();
		int index = tbItemServiceImpl.update(ids, (byte)2);
		//如果成功返回200状态
		if(index == 1) {
			egoResult.setStatus(200);
		}
		return egoResult;
	}
	/**
	 * 商品上架
	 * @param ids
	 * @return
	 */
	@RequestMapping("rest/item/reshelf")
	@ResponseBody
	public EgoResult reshelf(String ids) {
		//商品状态实体类
		EgoResult egoResult = new EgoResult();
		int index = tbItemServiceImpl.update(ids, (byte)1);
		//如果成功返回200状态
		if(index == 1) {
			egoResult.setStatus(200);
		}
		return egoResult;
	}
}
